﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO_DTO_WS.DAO;
using DAO_DTO_WS.DTO;

namespace LayoutTemplate
{
    public partial class WebForm16 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if ((Session["ID"].ToString() == "") || (int.Parse(Session["TinhTrang"].ToString()) != 3))
                Response.Redirect("TrangLoi.aspx?Error=9");
        }

        protected void btnCapNhat_Click(object sender, EventArgs e)
        {
            int id = int.Parse(Request.QueryString["id"]);
            DoanhNghiepDTO doanhnghiep = DoanhNghiepDAO.LayDNTheoMa(id);
            ThanhVienDTO thanhvien = ThanhVienDAO.LayThanhVien(doanhnghiep.TenDangNhap);
            
            if (string.Compare(tbTenDoanhNghiep.Text, string.Empty, true) != 0)
            {
                doanhnghiep.TenDoanhNghiep = tbTenDoanhNghiep.Text;
                thanhvien.HoTen = tbTenDoanhNghiep.Text;
            }
            if (string.Compare(tbDiaChi.Text, string.Empty, true) != 0)
                doanhnghiep.DiaChi = tbDiaChi.Text;

            if (string.Compare(tbDienThoai.Text, string.Empty, true) != 0)
            {
                thanhvien.DienThoai = tbDienThoai.Text;
                doanhnghiep.DienThoai = tbDienThoai.Text;
            }

            if (string.Compare(tbWebsite.Text, string.Empty, true) != 0)
                doanhnghiep.WebSite = tbWebsite.Text;
            if (string.Compare(tbmk.Text, string.Empty, true) != 0)
                doanhnghiep.MatKhau = tbmk.Text;
            DoanhNghiepDAO.SuaDN(doanhnghiep);
            ThanhVienDAO.SuaTV(thanhvien);
        }

        protected void btnBlock_Click(object sender, EventArgs e)
        {
            int id = int.Parse(Request.QueryString["id"]);
            DoanhNghiepDTO doanhnghiep = DoanhNghiepDAO.LayDNTheoMa(id);
            ThanhVienDTO thanhvien = ThanhVienDAO.LayThanhVien(doanhnghiep.TenDangNhap);
            if (doanhnghiep.TinhTrang == 1)
            {
                doanhnghiep.TinhTrang = 0;
                thanhvien.TinhTrang = 0;
            }
            else
            {
                doanhnghiep.TinhTrang = 1;
                thanhvien.TinhTrang = 1;
            }
            DoanhNghiepDAO.SuaDN(doanhnghiep);
            ThanhVienDAO.SuaTV(thanhvien);
            Response.Redirect("AdminDanhSach.aspx?id=2&tt=0&page=1");
        }
    }
}
